﻿@using OpusSuite.Helpers

@model OpusSuite.ViewModels.AccountAdmin.LogonModel

@{
    ViewBag.Title = "Logon";
}

@Html.ValidationSummary(false)

<header>
<h1>Welcome to Opus Suite, property management software for owners and occupiers</h1>
<br/>
<h2>@ViewBag.Title</h2>
</header>

<br/>
<br/>

@using (Html.BeginForm("Logon", "AccountAdmin", FormMethod.Post, new { id = "LogonForm" }))
{
    <ul data-role="listview" data-inset="true">
        <li data-role="list-divider">Details</li>

        <li data-role="fieldcontain">
            @Html.LabelFor(model => model.UserName, new { @class = "label-horiz" })
            @Html.TextBoxFor(model => model.UserName, new { @class = "editor-horiz validate[required]" })
        </li>

        <li data-role="fieldcontain">
            @Html.LabelFor(model => model.Password, new { @class = "label-horiz" })
            @Html.PasswordFor(model => model.Password, new { @class = "editor-horiz validate[required]" })
        </li>

        <li data-role="fieldcontain">
            @Html.LabelFor(model => model.DatabaseName, new { @class = "label-horiz" })
            @Html.TextBoxFor(model => model.DatabaseName, new { @class = "editor-horiz validate[required]" })
        </li>

        <li data-role="fieldcontain">
            @Html.LabelFor(model => model.ServerName, new { @class = "label-horiz" })
            @Html.TextBoxFor(model => model.ServerName, new { @class = "editor-horiz validate[required]" })
        </li>

        <li data-role="fieldcontain">
            @Html.LabelFor(model => model.ServerType, new { @class = "label-horiz" })
            @Html.EnumDropDownListFor(model => model.ServerType, new { @class = "editor-horiz validate[required]" })
        </li>

        <li data-role="fieldcontain">
            <input id="login" type="submit" value="Login" />
        </li>
    </ul>
}

<script type="text/javascript">
    $(document).ready(function () {
        $("#login").button();
        $("#UserName").focus();
    });

    $("#login").click(function (e) {
        e.preventDefault();

        $("form").validationEngine('attach', { promptPosition: "topRight", autoPositionUpdate: true });

        if ($("form").validationEngine('validate')) {
            $("#progressSpinner").progressSpinner('open', {
                'title': 'Opus Suite - Logging in',
                'imgUrl': '/Content/themes/south-street/progress-spinner.gif")',
                'waitText': 'Logging in, please wait'
            });
            $(document).oneTime(200, function () {
                $("form").submit();
            });
        }
    });
</script>
